﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace FYPDemo
{
    public class Survey
    {
        public static DataTable listVendor()
        {
            SqlDataAdapter da = new SqlDataAdapter();
            DataTable dt = new DataTable();

            conndb db = new conndb();
            SqlConnection con = db.GetOpenConnection();
            SqlCommand cmd = con.CreateCommand();

            try
            {
                cmd.CommandText = "listVendor";
                cmd.CommandType = CommandType.StoredProcedure;

                da.SelectCommand = cmd;
                da.Fill(dt);
            }

            catch (Exception ex)
            {
                con.Close();
                throw ex;
            }

            finally
            {
                con.Close();
            }

            return dt;
        }

        public static int insertSurveyFeedback(string name, int vendor, int a1, int a2, int a3, int a4, int a5, string comment)
        {
            int result = 0;

            conndb db = new conndb();
            SqlConnection con = db.GetOpenConnection();
            SqlCommand cmd = con.CreateCommand();

            try
            {
                cmd.CommandText = "insertSurveyFeedback";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new SqlParameter("@Name", SqlDbType.VarChar, 50));
                cmd.Parameters["@Name"].Value = name;

                cmd.Parameters.Add(new SqlParameter("@Vendor", SqlDbType.Int));
                cmd.Parameters["@Vendor"].Value = vendor;

                cmd.Parameters.Add(new SqlParameter("@A1", SqlDbType.Int));
                cmd.Parameters["@A1"].Value = a1;

                cmd.Parameters.Add(new SqlParameter("@A2", SqlDbType.Int));
                cmd.Parameters["@A2"].Value = a2;

                cmd.Parameters.Add(new SqlParameter("@A3", SqlDbType.Int));
                cmd.Parameters["@A3"].Value = a3;

                cmd.Parameters.Add(new SqlParameter("@A4", SqlDbType.Int));
                cmd.Parameters["@A4"].Value = a4;

                cmd.Parameters.Add(new SqlParameter("@A5", SqlDbType.Int));
                cmd.Parameters["@A5"].Value = a5;

                cmd.Parameters.Add(new SqlParameter("@Comment", SqlDbType.VarChar, 200));
                cmd.Parameters["@Comment"].Value = comment;

                result = cmd.ExecuteNonQuery();
            }

            catch (Exception ex)
            {
                con.Close();
                throw ex;
            }

            finally
            {
                con.Close();
            }


            return result;
        }   
    }
}